package com.hongawen.interrupted;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年12月24日 10:24
 */
public class Interrupt {

    public static void main(String[] args) throws InterruptedException {

        Thread thread =new Thread(() ->{
            while (true){
                Thread local = Thread.currentThread();
                if(local.isInterrupted()){
                    System.out.println("当前线程被打断");
                    break;
                }
                System.out.println(LocalDateTime.now());
            }
        });
        thread.start();
        TimeUnit.SECONDS.sleep(2);
        thread.interrupt();

    }

}


